//
// Created by 32827 on 2023/11/26.
//
#include "yzl_i2c_lcd1306.h"
#if YZLED1306
YZF_RESULT yzl_1306_open(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_OPEN};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_close(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_CLOSE};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_light_screen(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_LIGHT_SCREEN};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_content_screen(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_CONTENT_SCREEN};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_light_level_screen(YZF_I2C_POINTER hi2c, uint8_t level){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LIGHT_LEVEL_SCREEN,level};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_light_by_1(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_LIGHT_BY_1};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_light_by_0(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_LIGHT_BY_0};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_ram_inc_set(YZF_I2C_POINTER hi2c, uint8_t mode){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_RAM_SET_INC_MODE,mode};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_ram_line_start_end_set(YZF_I2C_POINTER hi2c, uint8_t start, uint8_t end){
    uint8_t cmd[4]={YZL_1306_COMMAND,YZL_1306_SET_LINE_START_END,start,end};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,4);
}
YZF_RESULT yzl_1306_ram_page_start_end_set(YZF_I2C_POINTER hi2c, uint8_t start, uint8_t end){
    uint8_t cmd[4]={YZL_1306_COMMAND,YZL_1306_SET_PAGE_START_END,start,end};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,4);
}
YZF_RESULT yzl_1306_col_low_set(YZF_I2C_POINTER hi2c, uint8_t col_low){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_COL_LOW_BASE+col_low};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_col_high_set(YZF_I2C_POINTER hi2c, uint8_t col_high){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_COL_HIGH_BASE+col_high};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_data_write(YZF_I2C_POINTER hi2c, uint8_t data){
    uint8_t cmd[2]={YZL_1306_DATA, data};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_datas_write(YZF_I2C_POINTER hi2c, uint8_t* data,uint16_t len){
    return yz_i2c_add7_mem_transmit(hi2c,YZL_1306_ADDRESS_USE,YZL_1306_DATA,data,len);
}
YZF_RESULT yzl_1306_page_set(YZF_I2C_POINTER hi2c, uint8_t page){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_PAGE_BASE+page};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_lines_set(YZF_I2C_POINTER hi2c, uint8_t level){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LED_LINES,level};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_clock_set(YZF_I2C_POINTER hi2c, uint8_t reg_data){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LED_CLOCK,reg_data};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_y_offset_set(YZF_I2C_POINTER hi2c,uint8_t offset){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LED_Y_OFFSET,offset};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
///屏幕是否和内存同步
YZF_RESULT yzl_1306_dynamic_screen(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_DYNAMIC_SCREEN};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_static_screen(YZF_I2C_POINTER hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_STATIC_SCREEN};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_direction_set(YZF_I2C_POINTER hi2c, uint8_t direction){
    uint8_t cmd[2]={YZL_1306_COMMAND,direction};
    return yz_i2c_add7_transmit(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}

#if USE_SOFT_PORT
YZF_RESULT yzl_1306_soft_open(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_OPEN};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_close(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_CLOSE};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_light_screen(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_LIGHT_SCREEN};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_content_screen(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_CONTENT_SCREEN};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_light_level_screen(YZL_Soft_I2C* hi2c, uint8_t level){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LIGHT_LEVEL_SCREEN,level};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_soft_light_by_1(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_LIGHT_BY_1};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_light_by_0(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_LIGHT_BY_0};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_ram_inc_set(YZL_Soft_I2C* hi2c, uint8_t mode){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_RAM_SET_INC_MODE,mode};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_soft_ram_line_start_end_set(YZL_Soft_I2C* hi2c, uint8_t start, uint8_t end){
    uint8_t cmd[4]={YZL_1306_COMMAND,YZL_1306_SET_LINE_START_END,start,end};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,4);
}
YZF_RESULT yzl_1306_soft_ram_page_start_end_set(YZL_Soft_I2C* hi2c, uint8_t start, uint8_t end){
    uint8_t cmd[4]={YZL_1306_COMMAND,YZL_1306_SET_PAGE_START_END,start,end};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,4);
}
YZF_RESULT yzl_1306_soft_col_low_set(YZL_Soft_I2C* hi2c, uint8_t col_low){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_COL_LOW_BASE+col_low};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_col_high_set(YZL_Soft_I2C* hi2c, uint8_t col_high){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_COL_HIGH_BASE+col_high};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_data_write(YZL_Soft_I2C* hi2c, uint8_t data){
    uint8_t cmd[2]={YZL_1306_DATA, data};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_datas_write(YZL_Soft_I2C* hi2c, uint8_t* data,uint16_t len){
    uint8_t datap=YZL_1306_DATA;
    return yzl_softport_i2c_param_write(hi2c,YZL_1306_ADDRESS_USE,&datap,1,data,len);
}
YZF_RESULT yzl_1306_soft_page_set(YZL_Soft_I2C* hi2c, uint8_t page){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_PAGE_BASE+page};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_lines_set(YZL_Soft_I2C* hi2c, uint8_t level){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LED_LINES,level};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_soft_clock_set(YZL_Soft_I2C* hi2c, uint8_t reg_data){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LED_CLOCK,reg_data};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
YZF_RESULT yzl_1306_soft_y_offset_set(YZL_Soft_I2C* hi2c,uint8_t offset){
    uint8_t cmd[3]={YZL_1306_COMMAND,YZL_1306_LED_Y_OFFSET,offset};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,3);
}
///屏幕是否和内存同步
YZF_RESULT yzl_1306_soft_dynamic_screen(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_DYNAMIC_SCREEN};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_static_screen(YZL_Soft_I2C* hi2c){
    uint8_t cmd[2]={YZL_1306_COMMAND,YZL_1306_STATIC_SCREEN};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
YZF_RESULT yzl_1306_soft_direction_set(YZL_Soft_I2C* hi2c, uint8_t direction){
    uint8_t cmd[2]={YZL_1306_COMMAND,direction};
    return yzl_softport_i2c_write(hi2c,YZL_1306_ADDRESS_USE,cmd,2);
}
#endif
#endif